package old.galaxyGeneration;

import objects.GameSettings;
import objects.Universe;
import objects.physicalEntities.Star;
import inputOutput.PlayerSettings;
import inputOutput.XMLoader;

public class ClusterGalaxy extends Galaxy 
{
	//XML
	//--------------------------------------------------
	protected double clusterStdDevFactor;// = 7
	//--------------------------------------------------
	
	public ClusterGalaxy(){}

	public ClusterGalaxy(GameSettings gameSettings, Universe universe) 
	{		
		super(gameSettings, universe);
		this.clusterStdDevFactor = gameSettings.getClusterStdDevFactor();
		this.galaxyGenerator();
	}

	protected void galaxyGenerator()
	{
		System.out.println("Just inside Cluster");
		
		double starBorderZone1 = 3;  //border region where no clusters may be placed (left)
		double starBorderZone2 = uniLength-4;  //border region where no clusters may be placed (right)
		
		//Reset array (just in case)
		for (int i = 0; i < uniLength; i++)
		{
			for (int j = 0; j < uniLength; j++)
			{
				starGrid[i][j] = 0;
			}
		}
		
		//create and place stars
		for (starsPlaced = 0; starsPlaced < numStars; starsPlaced++)
		{
			//System.out.println("1");
			//uniLength/4 offsets to the edge of the workingLength grid
			//workingLength/2 offsets to the center of the workingLength grid
			//nextGaussian() generates a gaussian dist. random variable centered at 0, std. dev 1
			tempX = uniLength/4+workingLength/2+randG1.nextGaussian()*workingLength/clusterStdDevFactor;
			tempY = uniLength/4+workingLength/2+randG2.nextGaussian()*workingLength/clusterStdDevFactor;
			
			x = (int)tempX;
			y = (int)tempY;
			
			//System.out.println(uniLength);
			System.out.println("x= " + x + " y= " + y);
			
			//check that generated star coords are within the grid and not near edges
			if ((x > starBorderZone1) & (y > starBorderZone1) & (x < starBorderZone2) & (y < starBorderZone2))
			{	
				//System.out.println("2");
				//check starGrid values at location
				if (starGrid[x][y] == 0)
				{
					universe.AddStar(new StarModel(x,y));
					updateGrid(x,y);					
				}

				else if ((starGrid[x][y] == 1) & (randUni.nextDouble() < ringTwo))
				{
					universe.AddStar(new StarModel(x,y));
					updateGrid(x,y);						
				}

				else if ((starGrid[x][y] == 2) & (randUni.nextDouble() < ringOne))
				{
					universe.AddStar(new StarModel(x,y));
					updateGrid(x,y);
				}
				else
				{starsPlaced -= 1;}
				//if outside the grid, subt 1 from i, loop again
			}
			else 
			{starsPlaced -= 1;}
		}		
		universe.PrintStars();
	}

	public double getClusterStdDevFactor() {
		return clusterStdDevFactor;
	}

	public void setClusterStdDevFactor(double clusterStdDevFactor) {
		this.clusterStdDevFactor = clusterStdDevFactor;
	}
	
	
}
